<template>
	<view class="home">
		<swiper 
		:indicator-dots="true" 
		:autoplay="true"
		 :interval="3000"
		  :duration="1000">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img" mode=""></image>
			</swiper-item>
		</swiper>
		<view class="nav">
			<view class="nav_item" @click="navItemClick('/pages/goods/goods')">
				<view></view>
				<text>超市</text>
			</view>			
			<view class="nav_item" @click="navItemClick('/pages/contact/contact')">
				<view></view>
				<text>联系我们</text>
			</view>			
			<view class="nav_item" @click="navItemClick('/pages/pics/pics')">
				<view></view>
				<text>社区图片</text>
			</view>			
			<view class="nav_item" @click="navItemClick('/pages/videos/videos')">
				<view></view>
				<text>学习视频</text>
			</view>
		</view>
		<!--推荐商品-->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<goods-list :goods='goods' @goodsItemClick="goGoodsDetail"></goods-list>
		</view>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				swipers:[],
				goods:[],
				nav:[]
			}
		},
		onLoad() {
			this.getSwipers();
			this.getHotGoods();
		},
		components:{'goods-list':goodsList},
		methods: {
			// getSwipers(){
			// 	uni.request({
			// 		url:'http://localhost:8082/api/getlunbo',
			// 		success: res =>{
			// 			if(res.data.status !==0){
			// 				return uni.showToast({
			// 					title:'获取数据失败'
			// 				})
			// 			}
			// 			this.swipers =res.data.message
			// 		}
			// 	})
			// }
			// async getSwipers(){
			// 	const res = await uni.request({
			// 		url:'http://localhost:8082/api/getlunbo'
			// 	})
				// console.log(res)
			// }
			async getSwipers(){
					const res = await this.$myRequest({
						url:'/api/getlunbo'
					})
					// console.log(res)
					this.swipers =res.data.message
				},
			async getHotGoods () {
					const res =await this.$myRequest({
						url:'/api/getgoods?pageindex=1'
					})
					this.goods =res.data.message
			},
			navItemClick(url){
				// console.log(e)
				uni.navigateTo({
					url
				})
			},
			goGoodsDetail(id){
				uni.navigateTo({
					url:'/pages/goods-detail/goods-detail?id='+id
				})
			}
		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.nav{
			display: flex;
			.nav_item{
				width: 25%;
				text-align: center;
				view{
					width: 120rpx;
					height: 120rpx;
					background: #b50e03;
					border-radius: 60rpx;
					margin: 10rpx auto;
					line-height: 120rpx;
					color: #FFFFFF;
				}
				text{
					font-size: 30rpx;
				}
			}
		}
		.hot_goods{
			overflow: hidden;
			background-color: #eee;
			.tit{
				height: 50px;
				line-height: 50px;
				color: #b50e03;
				text-align: center;
				background: #FFFFFF;
				margin: 10rpx 0;
			}
		}
	}
</style>
